<?php if(!defined('DB_NAME')) die();
// 变量设置
global $ver;
if( is_single() && get('ini_single') || get('ini_layout')=="关闭侧栏" ) $single = 1;
// 登录按钮
function login_button(){
	if( !get('ini_log') ) return;
	$output = '<div class="main-admin">';
	if( (current_user_can('level_0')) ){
		global $current_user;
		$output.= '<a class="wp-admin" href="'. get_bloginfo('url') .'/wp-admin/"><span class="detail">查看仪表盘</span>' . get_avatar( $current_user->user_email, 20) . $current_user->nickname . '</a>';
		$output.= '<a class="log logout" href="'. wp_logout_url($_SERVER["REQUEST_URI"]) .'">退出</a>';
	} else {
		$output.= '<a id="main-login" class="log" href="javascript:;">登录</a>';
	}
	$output.= '</div>';
	return $output;
}
?>
<!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1">
<?php
//SEO优化,标题格式,描述,关键词
ini_seo();
if( !ismobile() ){
	//桌面输出
	if( is_singular() ){
		//谷歌富文本
		echo "<meta property=\"v:url\" content=\"".get_permalink()."\">\n";
		echo "<meta property=\"v:type\" content=\"article\">\n";
		//评论分页添加nofollow
		if( function_exists('get_query_var') ) {
			$cpage = intval(get_query_var('cpage'));
			$commentPage = intval(get_query_var('comment-page'));
		}
		if( !empty($cpage) || !empty($commentPage) ) {
			echo '<meta name="robots" content="noindex, nofollow">';
			echo "\n";
		}
	}
	if( isIE8() ) echo "<meta http-equiv=\"X-UA-Compatible\" content=\"IE=EDGE,chrome=1\">\n";
	echo "<link rel=\"pingback\" href=\"".get_bloginfo('pingback_url')."\">\n";
	echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"" . TPDIR . "/res/css/initial.css?ver=$ver\">\n";
	echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"" . TPDIR . "/res/css/font-awesome.css?ver=$ver\">\n";
} else {
	//手机输出
	echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"" . TPDIR . "/res/css/mobile.css?ver=$ver\">\n";
}
?>
<link rel="stylesheet" type="text/css" href="<?php echo TPDIR?>/res/css/custom.css?<?php echo 'ver=' . filesize(dirname(__FILE__) . '/res/css/custom.css')?>">
<link rel="shortcut icon" href="<?php echo get("ini_fav")?>" type="image/x-icon">
<?php
$jquery = TPDIR .'/res/js/jquery.js?ver=1.11.1';
if(get('ini_jquery')=='七牛CDN') $jquery = "http://cdn.staticfile.org/jquery/1.11.1/jquery.min.js";
if(get('ini_jquery')=='百度CDN') $jquery = "http://libs.baidu.com/jquery/1.11.1/jquery.min.js";
if(get('ini_jquery')=='微软CDN') $jquery = "http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.11.1.min.js";
if(get('ini_jquery')=='CDNJS') $jquery = "http://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.1/jquery.min.js";
echo "<script src=\"$jquery\"></script>\n";
if( isIE8() ) echo "<script src=\"" . TPDIR . "/res/js/html5.js\"></script>\n";
?>
<script><?php
//悬停模块
if( is_home() ) $roll=explode(',',get('ini_roller_home'));
if( is_archive()||is_search() ) $roll=explode(',',get('ini_roller_arch'));
if( is_single() ) $roll=explode(',',get('ini_roller'));
//Fancybox设定
if( get('ini_fb_eff') ) $fb_eff = 'fb_eff:"'.get('ini_fb_eff').'",';
if( get('ini_fb_tit') ) $fb_tit = 'fb_tit:"'.get('ini_fb_tit').'",';
if( get('ini_fb_til') ) $fb_til = 'fb_til:"'.get('ini_fb_til').'",';
$fb_nav = (get('ini_fb_nav'))? "fb_nav:true,": "";
$fb_aut = (get('ini_fb_aut'))? "fb_aut:true,": "";
$fb_tog = (get('ini_fb_tog'))? "": "fb_tog:false,";
$fb_spe = (get('ini_fb_spe'))? "fb_spe:".get('ini_fb_spe').",": "";
$fb_tim = (get('ini_fb_tim'))? "fb_tim:".get('ini_fb_tim').",": "";
$fb_siz = (get('ini_fb_siz'))? "fb_siz:".get('ini_fb_siz').",": "";
//Fancybox和Prettify开关
$fbox = 0;$pret = 0;
if( !ismobile() || ismobile() && get('ini_mfbox') ) $fbox = 1;
if( !ismobile()&&get('ini_prettify') || ismobile()&&get('ini_prettify')&&get('ini_mpret') ) $pret = 1;
//媒体文章悬停
$meheader = $single == 1 ? "meheader:0," : "meheader:1,";
//页头脚本开关
?>
window.ini={name:"<?php bloginfo('name')?>",home:"<?php bloginfo('url')?>",path:"<?php get('ini_path') ? print get('ini_path'): "Initial"?>",<?php if (get('ini_fancybox')&&is_singular()){ echo "fbox:$fbox,{$fb_eff}{$fb_spe}{$fb_nav}{$fb_tog}{$fb_aut}{$fb_tim}{$fb_tit}{$fb_til}{$fb_siz}{$meheader}";} if ($pret==1&&is_singular()) echo "pret:1,"; if( !is_page() ) echo "c:".$roll[0].",d:".$roll[1].",e:".$roll[2].","?>time:<?php echo get('ini_focus_time') ? get('ini_focus_time'): 4000?>,rate:<?php echo get('ini_bulletin_rate') ? get('ini_bulletin_rate'): 3000?>}</script>
<style><?php
//样式修改
if( !ismobile() && function_exists('themedie') ){
	if( $single!=1 || !is_page() && !ismedia() ){ if( get('ini_layout')=="侧栏在左" ) echo "#content{float:right}#sidebar,#meheader{float:left;margin:0 -320px 0 0}.main{margin:0 0 10px 330px}.cat-post{margin:0 0 0 330px}@media screen and (max-width:800px){.main,.cat-post{margin-left:0}}"; }
	if( $single == 1 ) echo ".immax{max-width:960px}.main{margin:0 0 10px 0}#meheader{width:100%;float:none;margin:0;padding-left:320px;position:relative}#meheader .cover{height:100%;position:absolute;top:0;left:0}#meheader .entry-title{text-align:left}#meheader .mecontext{min-height:320px}"; #文章单栏布局
	if( get('ini_width') ){ echo ".immax{max-width:".get('ini_width')."px}";}  #页面最大宽度
	if( get('ini_no_thumb') ) echo ".rand-item button:hover{opacity:.7}"; #无图模式
	//修复评论头像
	$size = get('ini_avatar')? get('ini_avatar'): 40;
	$left = $size + 20;
	if( !ismobile() ) echo ".comment-content{margin-left:{$left}px}.comment-list img.avatar{left:-{$left}px}";
}
if( ismobile() && get('ini_mnav_h') ){
	$height = get('ini_mnav_h').'px';
	$logom = (get('ini_mnav_h')-40)/2;
	echo "#nav{height:$height;line-height:$height}#menu{top:$height}#nav-logo a{margin-top:{$logom}px}#container{margin-top:$height}";
}
if( $pret==0 ) echo "pre.prettyprint{padding:6px 12px!important;white-space:pre}"; #代码高亮修正
?>
</style>
<?php wp_head()?>
</head>

<body <?php body_class()?>>
<div id="nav">
	<div id="nav-item" class="immax">
		<h1 id="nav-logo"><a href="<?php bloginfo('url')?>" style="<?php
		if( get('ini_logo') ):
			$logoStyle = "background-image:url(".get("ini_logo").")";
			if( isIE8() ) $logoStyle = "filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=".get("ini_logo").",sizingMethod='scale')";
			echo $logoStyle;
		endif;
		?>"><?php bloginfo('name')?></a></h1>
		<?php
echo ismobile()? "<div id='nav-switch'></div>": "<button id='nav-switch' class='hide'></button>\n";
//加载导航菜单
if(function_exists('wp_nav_menu') && $obj_key  == $ini_key && ismobile() ) {
	echo '<div id="menu">';
	echo login_button();
	echo "<form id='nav-search' method='get' action='" . get_bloginfo('url') . "'><input type='submit' class='button' value='&#xe011;'><input type='text' name='s' placeholder='请输入关键词'></form>\n";
	wp_nav_menu( array(
		'theme_location' => 'mobile',
		'menu_id' => '',
		'menu_class' => 'mobile-menu',
		'after' => '<span></span>',
		'container' => 'false',
		'items_wrap' => '<ul class="%2$s">%3$s</ul>',
		'fallback_cb' => 'nav_fallback' )  #导航回调
	);
	echo '</div>';
} else {
	wp_nav_menu( array(
		'theme_location' => 'primary',
		'menu_id' => 'menu',
		'menu_class' => 'nav-menu',
		'container' => 'false',
		'fallback_cb' => 'nav_fallback',
		'walker' => new description_walker() )
	);
}
?> 
<?php if( !ismobile() && ! get( 'ini_mark') ):?>
		<div id="nav-btn">
			<a class="nav-button icon-search" id="tog-search" href="javascript:;"></a>
			<a class="nav-button icon-rss" id="tog-rss" href="<?php echo get('ini_qqlist') ? 'javascript:;' : bloginfo('rss2_url'). '" rel="external' ?>"></a>
<?php if( get('ini_qqlist') ){ ?>
			<div id="love-rss" class="hide">
				<a href="<?php echo bloginfo('rss2_url')?>" rel="external">RSS订阅</a>
				<form action="http://list.qq.com/cgi-bin/qf_compose_send" rel="external" method="post">
					<input type="hidden" name="t" value="qf_booked_feedback">
					<input type="hidden" name="id" value="<?php echo get('ini_qqlist')?>">
					<input type="text" name="to" id="to" placeholder="输入邮箱，订阅本站">
					<input type="submit" id="confirm-rss" value="确认订阅">
				</form>
			</div>
<?php } ?>
		</div><?php#end nav-btn?> 
<?php else: echo "<div id='nav-cmt'></div>"?>
<?php endif?>
	</div><?php#end nav-item?> 
</div>
<?php if( !ismobile() ) echo '<form id="nav-search" method="get" action="' . get_bloginfo('url') . '"><i class="icon-search"></i><input type="search" placeholder="请输入关键词并按回车键" value="" name="s" x-webkit-speech></form>'?>

<?php
if( ismobile() && !get('ini_mark' ) && $obj_key==$ini_key ):
	include 'mp/header.php';
else:
echo "<div id=\"mainbar\" class=\"clear\">\n";
if( !is_page() && !get( 'ini_mark' ) && get('ini_metro')=="显示" ):
	if( is_home()||is_archive()||get('ini_metro_s')=="显示" ){
?>
	<div id="metro" class="immax">
		<div id="featured">
			<ul id="featured-box">
<?php
		query_posts( 'meta_key=top&ignore_sticky_posts=1&showposts='.get('ini_num') );
		if(have_posts()):
			while (have_posts()): the_post();
				if (get('ini_no_thumb')){   #无图模式
					$colors = ini_color();
					$color = $colors[ rand(0,8) ];
					echo "<li><a rel=\"external\" href=\"".get_permalink()."\"><button style=background:$color>".get_the_title()."</button></a></li>";
				} else {
					ini_featured();
				}
			endwhile;
			else:
			query_posts( 'orderby=rand&ignore_sticky_posts=1&showposts='.get('ini_num') );
			while (have_posts()) : the_post();
				if (get('ini_no_thumb')){   #无图模式
					$colors = ini_color();
					$color = $colors[ rand(0,8) ];
					echo "<li><a rel=\"external\" href=\"".get_permalink()."\"><button style=background:$color>".get_the_title()."</button></a></li>";
				} else {
					ini_featured();
				}
			endwhile;
		endif;
		wp_reset_query();
?>
			</ul>
			<ul id="featured-li"></ul>
			<button id="featured-pre">&nbsp;‹</button>
			<button id="featured-nex">›&nbsp;</button>
		</div><?php#end metro featured?> 
		<div id="rand">
<?php
		$rand_num = get('ini_rand') ? get('ini_rand') : 20;
		$rand_posts = get_posts("ignore_sticky_posts=1&numberposts=$rand_num&category=".get('ini_cat_id'));
		shuffle($rand_posts);
		$i=0; foreach( $rand_posts as $post) :
			if($i<8) :
				$i++;
				$colors = ini_color();
				$color = $colors[ rand(0,8) ];
?>
			<a class="rand-item" href="<?php the_permalink()?>"><?php if(!get('ini_no_thumb')) echo ini_img(220,110)?><button<?php if(get('ini_no_thumb')) echo " style=top:0;background:$color"; ?>><?php the_title()?></button></a>
<?php
			endif;
		endforeach;
		wp_reset_query();
?>
			<div id="rand-loading"></div>
			<div id="rand-changer" class="btn slow"><i class="icon-refresh"></i>刷新换一批</div>
		</div><?php#end metro rand?> 
	</div><?php#end metro?> 
<?php
	}
endif;#ismedia?>
	<div id="main-detail" class="immax">
		<div class="main-likeus">
			<div class="main-follow">关注我们</div>
<?php if( get('ini_weibo') ){?>
			<a href="<?php echo get('ini_weibo')?>" rel="external nofollow"><i class="icon-weibo"></i><span class="detail">新浪微博</span></a>
<?php } ?>
<?php if( get('ini_tweibo') ){?>
			<a href="<?php echo get('ini_tweibo')?>" rel="external nofollow"><i class="icon-twb"></i><span class="detail">腾讯微博</span></a>
<?php } ?>
<?php if( get('ini_weixin') ){
	echo '			<a href="javascript:;" class="weixin"><i class="icon-weixin"></i>';
		$weixin = get('ini_weixin');
		if( is_singular() ) $link = get_permalink();
		echo "<span class='detail qrcode'><img src=\"$weixin\" alt=\"QRcode\"/></span>";
	echo "</a>\n";
} ?>
<?php if( get('ini_f') ){?>
			<a href="<?php echo get('ini_f')?>" rel="external nofollow"><i class="icon-facebook"></i><span class="detail">Facebook</span></a>
<?php } ?>
<?php if( get('ini_ggplus') ){?>
			<a href="https://plus.google.com/<?php echo get('ini_ggplus')?>" rel="external nofollow"><i class="icon-gg"></i><span class="detail">Google +</span></a>
<?php } ?>
<?php if( get('ini_tw') ){?>
			<a href="<?php echo get('ini_tw')?>" rel="external nofollow"><i class="icon-twitter"></i><span class="detail">Twitter</span></a>
<?php } ?>
			<a href="http://mail.qq.com/cgi-bin/qm_share?t=qm_mailme&amp;email=<?php get('ini_mail') ? print get('ini_mail') : bloginfo('admin_email')?>" rel="external nofollow"><i class="icon-mail"></i><span class="detail">邮件联系</span></a>
<?php if( get('ini_qrcode') ){
	echo '			<a href="javascript:;" class="qrcode"><i class="icon-qrcode"></i>';
		global $wp;
		$link = home_url( add_query_arg(array(), $wp->request) );
		if( is_singular() ) $link = get_permalink();
		echo "<span class='detail qrcode'>" . ini_QR($link) . "</span>";
	echo "</a>\n";
} ?>
		</div>
		<?php echo login_button()?> 
	</div><?#end main-detail?> 
</div><?php#end mainbar?>

<?php include "inc/bulletin.php"?>

<div id="container" class="clear immax">
<?php endif;#ismobile?>